package com.mall.b2c.bean;

import java.math.BigDecimal;
import java.util.Date;

import org.apache.commons.lang3.StringUtils;

import com.mall.b2c.domain.member.MemberDomain;
import com.mall.common.util.VerifyUtil;

public class MemberBean {
	private Long id;
	private String username;// 用户名
	private String name;// 真实姓名
	private String email;// 邮箱
	private String mobile;// 手机号码
	private String phone;//座机
	private Boolean sex;//性别
	private Date birthday;//生日
	private Integer point;// 积分
	private Integer intergral; //剩余积分
	private BigDecimal deposit;// 余额
	private String area;//区域全称
	private String areaTree;//区域id
	private String address;//地址
	private String bindEmail;//待绑定的邮箱

	public MemberBean() {
		super();
	}

	public MemberBean(MemberDomain member) {
		this.id = member.getId();
		this.username = member.getUsername();
		this.name = member.getName();
		this.email = member.getEmail();
		this.mobile = member.getMobile();
		this.point = member.getPoint();
		this.deposit = member.getDeposit();
		if(member.getArea() != null){
			this.area = member.getArea().getFull_name();
			this.areaTree = member.getArea().getFullPath();
		}
		this.address = member.getAddress();
		this.sex = member.getSex();
		this.birthday = member.getBirthday();
		this.phone = member.getPhone();
		String verifyCode = member.getEmailVerifyCode(1);
		if(StringUtils.isNotBlank(verifyCode)){
			this.bindEmail = VerifyUtil.getEmailFromVerifyCodeKey(verifyCode);
		}
		this.intergral = 0;
	}

	public String getFullAddress(){
		String full = area;
		if(StringUtils.isNotBlank(full)){
			if(StringUtils.isNotBlank(address)){
				full += address;
			}
		}else{
			if(StringUtils.isNotBlank(address)){
				full = address;
			}
		}
		return full;
	}

	public String getSafeMobile(){
		if(StringUtils.isBlank(mobile)){
			return null;
		}
		return mobile.substring(0, 3) + "*****" + mobile.substring(8);
	}

	public String getSafeEmail(){
		if(StringUtils.isBlank(email)){
			return null;
		}
		String[] strs = email.split("@");
		return strs[0].substring(0, 2) + "***@" + strs[1];
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public Integer getPoint() {
		return point;
	}

	public void setPoint(Integer point) {
		this.point = point;
	}

	public BigDecimal getDeposit() {
		return deposit;
	}

	public void setDeposit(BigDecimal deposit) {
		this.deposit = deposit;
	}

	public String getAreaTree() {
		return areaTree;
	}

	public void setAreaTree(String areaTree) {
		this.areaTree = areaTree;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public Boolean getSex() {
		return sex;
	}

	public void setSex(Boolean sex) {
		this.sex = sex;
	}

	public Date getBirthday() {
		return birthday;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getArea() {
		return area;
	}

	public void setArea(String area) {
		this.area = area;
	}

	public String getBindEmail() {
		return bindEmail;
	}

	public void setBindEmail(String bindEmail) {
		this.bindEmail = bindEmail;
	}


	public Integer getIntergral() {
		return intergral;
	}

	public void setIntergral(Integer intergral) {
		this.intergral = intergral;
	}
}
